package org.opens.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.opens.entity.LotteryHistory;
import org.opens.entity.vo.LotteryHistoryModifyWave;
import org.opens.entity.vo.LotteryHistorySumDistribution;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

@Mapper
@Component
public interface LotteryHistoryDao extends BaseMapper<LotteryHistory> {

    /**
     * 获取数据库中最新的limit条数据
     * @param limit 限制的条数
     */
    @Select(value = "select * from lottery_history where type = #{type} order by num_of_periods desc limit #{limit}")
    List<LotteryHistory> getTheLatest(@Param(value = "type") String type, @Param(value = "limit") int limit);

    /**
     * 说明:
     * <pre>
     *     1. 批量保存彩票开奖记录.
     * </pre>
     */
    public int saveBatch(@Param(value = "saveRes") Collection<LotteryHistory> saveRes);

    /**
     * 说明:
     * <pre>
     *     1. 彩票历史记录的分页查询方法.
     *     2. mybatis-plus的底层写法限制Page对象必须放在第一个参数上, 否则会报错.
     * </pre>
     */
    public IPage<LotteryHistory> page(
            Page<LotteryHistory> page,
            @Param(value = "searchParam") LotteryHistory lotteryHistory
    );

    /**
     * 说明:
     * <pre>
     *     1. 彩票立即记录的波动查询sql.
     * </pre>
     */
    public List<LotteryHistoryModifyWave> getModifyWave(@Param(value = "type") String type, @Param(value = "limit") int limit);

    /**
     * 说明:
     * <pre>
     *     1. 双色球专用方法, 计算和值的正态分布.
     * </pre>
     */
    public List<LotteryHistorySumDistribution> getSSQLotteryHistorySumDistribution();

}
